<?php

//测试控制器类
class IndexControl extends CommonControl
{
    public function __init()
    {
        //已经选择的游戏组不可再选择
        if (session('team')) {
            go('Question/question');
        }
    }

    function index()
    {
        header("Content-type:text/html;charset=utf-8");
        //删除缓存
        Dir::del('Temp');
        $this->display();
    }

    //选择答题组
    function select_team()
    {
        $db = M("team");
        $team = Q('team', null, 'strtolower');
        //-----------------每个组可以有多台电脑----------------
        $data = $db->where("team='$team'")->find();
        session('team', $data['team']);
        session('title', $data['title']);
        go('Question/question');

        //-----------------每个组只能有一台电脑----------------
        //判断选手组
//        if ($db->where("team='$team' and state=1")->find()) {
//            $this->error('队伍已经被别人选了,请重新选择');
//        } else {
//              更改组状态为选中
//            $db->where("team='$team'")->save(array('state' => 1));
//            $data = $db->where("team='$team'")->find();
//            session('team', $data['team']);
//            session('title', $data['title']);
//            go('Question/question');
//        }
    }

    /**
     * Ajax获得游戏组信息
     */
    public function get_team()
    {
        //每个组只能有一台电脑
//        $team = M('team')->where('state=0')->all();
        //每个组可以有多台电脑
        $team = M('team')->all();
        $this->ajax($team);
    }
}

